<?php
/**
 * @copyright ©2019 北京麦盟科技
 * Created by PhpStorm.
 * User: jack_guo
 * Date: 2019/7/4
 * Time: 11:22
 */

namespace app\plugins\region\controllers\api;

use app\core\response\ApiCode;
use app\plugins\region\models\RegionSetting;

class ApiController extends \app\controllers\api\ApiController
{
    public function beforeAction($action)
    {
        //权限判断
        $permission = \Yii::$app->branch->childPermission(\Yii::$app->mall->user->adminInfo);
        if (!in_array('region', $permission)) {
            \Yii::$app->response->data = ['code' => ApiCode::CODE_ERROR, 'msg' => '无区域代理权限'];
            return false;
        }
        //判断分红开关
        $model = RegionSetting::findOne(
            ['mall_id' => \Yii::$app->mall->id, 'key' => 'is_region', 'value' => '1', 'is_delete' => 0]
        );
        if (empty($model)) {
            \Yii::$app->response->data = ['code' => ApiCode::CODE_ERROR, 'msg' => '区域代理已关闭'];
            return false;
        }
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }
}
